package fx.iog.home;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import fx.iog.gen.R;

public class EventVipAdapter extends BaseAdapter {

	private List<RowEventVip> rowItems = new ArrayList<RowEventVip>();
	private LayoutInflater Inflater;

	public EventVipAdapter(Context context, int ImgPerfil, int nomePerfil,
			int imgEvt, int titEvt, int generoEvt, int dataEvt, int localEvento, int pontoEvt) {

		Inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		TypedArray imgPerfilArray = context.getResources().obtainTypedArray(
				ImgPerfil);
		
		String[] nomePerfilArray = context.getResources().getStringArray(
				nomePerfil);
		
		TypedArray imgEvtArray = context.getResources()
				.obtainTypedArray(imgEvt);
		
		String[] tituloEvtArray = context.getResources().getStringArray(titEvt);
		
		String[] generoEvtArray = context.getResources().getStringArray(generoEvt);

		String[] dataEvtArray = context.getResources().getStringArray(dataEvt);
		
		String[] localEventoArray = context.getResources().getStringArray(
				localEvento);
		
		String[] pontoEvtArray = context.getResources()
				.getStringArray(pontoEvt);

		for (int i = 0; i < nomePerfilArray.length; i++) {
			RowEventVip item = new RowEventVip(imgPerfilArray.getResourceId(i,
					-1), nomePerfilArray[i], imgEvtArray.getResourceId(i, -1),
					tituloEvtArray[i], generoEvtArray[i], dataEvtArray[i], localEventoArray[i],
					pontoEvtArray[i]);
			
			rowItems.add(item);
		}
	}

	@Override
	public int getCount() {
		return rowItems.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return rowItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return rowItems.indexOf(getItem(position));
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		ViewHolder holder = null;

		if (view == null) {

			view = Inflater.inflate(R.layout.vip_events_list, null);

			holder = new ViewHolder();

			holder.imgPerfil = (ImageView) view
					.findViewById(R.id.img_userevent_vip);
			
			holder.nomePerfil = (TextView) view.findViewById(R.id.txt_evtvip_nomeperfil);
			
			holder.imgEvento = (ImageView) view.findViewById(R.id.img_evtvip);
			
			holder.tituloEvento = (TextView) view.findViewById(R.id.txt_tituloevent_vip);
			
			holder.dataEvento = (TextView) view.findViewById(R.id.txt_vip_evtdata);
			
			holder.localEvento = (TextView) view.findViewById(R.id.txt_endevent_vip);
			
			holder.pontoEvento = (TextView) view.findViewById(R.id.txt_pointevent_vip);
			
			holder.generoEvento = (TextView) view.findViewById(R.id.txt_generoevent_vip);
			
			
			view.setTag(holder);

		} else {
			holder = (ViewHolder) view.getTag();
		}
		
		RowEventVip rowItem = rowItems.get(position);
	
		holder.imgPerfil.setImageResource(rowItem.getImgPerfil());
		holder.nomePerfil.setText(rowItem.getNomePerfil());
		holder.imgEvento.setImageResource(rowItem.getImgEvento());
		holder.tituloEvento.setText(rowItem.getTituloEvento());
		holder.generoEvento.setText(rowItem.getGeneroEvento());
		holder.dataEvento.setText(rowItem.getDataEvento());
		holder.localEvento.setText(rowItem.getLocalEvento());
		holder.pontoEvento.setText(rowItem.getPontoEvento());
		
		
		return view;
	}

	/* private view holder class */
	private class ViewHolder {

		public ImageView imgPerfil;
		public TextView nomePerfil;
		
		public ImageView imgEvento;
		public TextView tituloEvento;
		public TextView generoEvento;
		public TextView dataEvento;
		public TextView localEvento;
		public TextView pontoEvento;
	}
	

}
